<!DOCTYPE html>
<html>
    
    <head>
        <meta charset="utf-8">
        <title>X-admin v1.0</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="__PUBLIC__/X-admin/css/x-admin.css" media="all">
    </head>
    
    <body>
        <div class="x-body">
            <form class="layui-form" method="post" action="" >

                <div class="layui-form-item">
			        <label class="layui-form-label">所在班级</label>
			          <div class="layui-input-inline">
			            <select id="classs" name="class" lay-filter="classs" lay-verify="required">
			              <option value="">--请选择--</option>
			              <foreach name="classs" item="row" >
			              	<option value="{$row['id']}">{$row['name']}</option>
			              </foreach>
			            </select>
			        </div>
			    </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">学员姓名</label>
                      <div class="layui-input-inline">
                        <select id="name" name="name" lay-verify="required" lay-filter="username" >
                            <option value="">--请选择--</option>
                        </select>
                    </div>
                </div>
				 <div class="layui-form-item layui-form-text">
				    <label class="layui-form-label">扣分数</label>
				    <div class="layui-input-inline">
                        <select id="score" name="score" lay-verify="required" lay-filter="username" >
                            <option value="">--请选择--</option>
                            <option value="5">5分</option>
                            <option value="10">10分</option>
                            <option value="15">15分</option>
                            <option value="20">20分</option>
                            <option value="30">30分</option>
                            <option value="50">50分</option>
                            <option value="100">100分</option>
                        </select>
                    </div>
				  </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">扣分时间</label>
                      <div class="layui-input-inline">
                        <input class="layui-input" name="addtime" placeholder="yyyy-yy-yy" required="" lay-verify="required" autocomplete="off" id="LAY_demorange_s">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                  <label class="layui-form-label">扣分原因</label>
                  <div class="layui-input-block">
                    <textarea id="cause" name="cause" placeholder="请输入内容" class="layui-textarea"></textarea>
                  </div>
                </div>

				  <!-- <div class="layui-form-item layui-form-text">
				    <label class="layui-form-label">扣分时间</label>
				    <div class="layui-input-inline">
                        <input type="date" id="addtime" name="addtime" required="" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
				  </div> -->

                

                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button  class="layui-btn" lay-filter="add" lay-submit="">提交</button>
                </div>
            </form>
        </div>
        <script src="__PUBLIC__/X-admin/lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="__PUBLIC__/X-admin/js/x-layui.js" charset="utf-8">
        </script>
        <script>
            layui.use(['laydate','form','layer'], function(){
                $ = layui.jquery;
                laydate = layui.laydate;//日期插件
                var form = layui.form();
                layer = layui.layer;


                var start = {
                min: '2000-00-00 00:00:00'
                ,max: laydate.now()
                ,istoday: false
                ,choose: function(datas){
                  end.min = datas; //开始日选好后，重置结束日的最小日期
                  end.start = datas //将结束日的初始值设定为开始日
                }
              };
              
              // var end = {
              //   min: laydate.now()
              //   ,max: '2099-06-16 23:59:59'
              //   ,istoday: false
              //   ,choose: function(datas){
              //     start.max = datas; //结束日选好后，重置开始日的最大日期
              //   }
              // };

              document.getElementById('LAY_demorange_s').onclick = function(){
                start.elem = this;
                laydate(start);
              }
              // document.getElementById('LAY_demorange_e').onclick = function(){
              //   end.elem = this
              //   laydate(end);
              // };


                form.on('select(classs)', function(data){

                  classid = data.value;
                  // alert(classid);
                  $.ajax({
                    "url":"__MODULE__/Punish/select",
                    "data":{classid:classid},
                    'type':"post",
                    "dataType":"json",
                    success:
                    function(data){

                        select=$("#name");
                        select.empty();
                        select.append("<option value='' >--请选择--</option>");
                        if(data.length>0){
                        //遍历
                            for(var i=0;i<data.length;i++){
                                //把遍历出来数据添加到option
                                info='<option  value="'+data[i].id+'">'+data[i].name+'</option>';
                                select.append(info);
                                form.render('select');
                            }
                        
                        }
                    }
                  });
                }); 

              //监听提交
              form.on('submit(add)', function(data){
                
                console.log(data);

                classs = $("#classs").val();    //所在班级
                name = $("#name").val();    //学员的users中的id值
                cause = $("#cause").val();  //扣分原因
                score = $("#score").val();  //扣分值
                addtime = $("#LAY_demorange_s").val();        //扣分时间
                // alert(addtime);
                $.post('__MODULE__/Punish/insert',{classs:classs,name:name,cause:cause,score:score,addtime:addtime},function(data){
                    if(data=="添加成功"){

                    }else{
                        alert('数据添加失败');
                        return false;
                    }
                });
                layer.alert("添加成功", {icon: 6},function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                    parent.reload();
                });
                return false;
              });
            }); 


        </script>
    </body>

</html>